//
//  HChooseBankViewController.m
//  NursingManages
//
//  Created by Zhen Huang on 17/9/14.
//  Copyright © 2017年 huangzhen. All rights reserved.
//

#import "HChooseBankViewController.h"
#import "DIHTest.h"
#import "Model_Hr_Quesbank_Type.h"
@interface HChooseBankViewController ()
<UITableViewDelegate,
UITableViewDataSource>

@property (nonatomic, strong) UITableView *tabelview;
@property (nonatomic, strong) NSArray *array;
@property (nonatomic, strong) NSMutableArray *dataArray;

@end

@implementation HChooseBankViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.dataArray = [NSMutableArray new];
    DIHTest *HTest = [[DIHTest alloc]init];
    self.array = [HTest getQuesBankTitle];
    
    for (Model_Hr_Quesbank_Type *model in self.array) {
        
        NSArray *array = [HTest getQuesBankNameWithBankid:model.BANKID];
        [self.dataArray addObject:array];
    }
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tabelview];
    self.navigationController.navigationBar.barTintColor = kNavBlueColor;
    self.navigationController.navigationBar.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]};
    
    UIBarButtonItem *execbtn = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancel:)];
    self.navigationItem.rightBarButtonItem = execbtn;

    
}

- (UITableView *)tabelview
{
    if (!_tabelview) {
        _tabelview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) style:UITableViewStylePlain];
        _tabelview.dataSource = self;
        _tabelview.delegate = self;
        [_tabelview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
        _tabelview.tableFooterView = [[UIView alloc]init];
    }
    return _tabelview;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSArray *array = self.dataArray[section];
    return array.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray *array = self.dataArray[indexPath.section];
    Model_Hr_Quesbank_Type *model = array[indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.textLabel.text = model.BANKNAME;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    NSArray *array = self.dataArray[indexPath.section];
    Model_Hr_Quesbank_Type *model = array[indexPath.row];
    self.getBlock(model);
    [self dismissViewControllerAnimated:YES completion:NULL];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.array.count;
}
- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{

    Model_Hr_Quesbank_Type *model = self.array[section];

    return model.BANKNAME;
}
- (void)cancel:(UIButton *)sender {
    
    [self dismissViewControllerAnimated:YES completion:NULL];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
